﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace FrontAfterSeparate.Controllers
{
    [Route("[controller]/[action]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        [HttpPost]
        public LoginResponse Login(LoginRequest req)
        {
            if (req.UserName == "admin" && req.Password == "123456")
            {
                var items = Process.GetProcesses().Select(a=>new ProcessInfo(a.Id,a.ProcessName,a.WorkingSet64)).ToArray();
                return new LoginResponse(true,items);
            }
            else
            {
                return new LoginResponse(false, null);
            }
        }
    }

    public record LoginRequest(string UserName,string Password);

    public record ProcessInfo(long Id,string Name,long WorkingSet);

    public record LoginResponse(bool OK,ProcessInfo[]? ProcessInfos);

}
